package com.rtst.widget.listview;

import android.content.Context;
import android.os.AsyncTask;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;

public abstract class AbstractListBuilder extends AbstractBuilder {
	protected BaseAdapter mAdapter;
	public AbstractListBuilder(Context context, ViewGroup parent) {
		super(context, parent);
	}

	@Override
	protected void buildLayout(ViewGroup parent) {
		
		ListView listView = (ListView) parent
				.findViewById(android.R.id.list);
		mAdapter = new MyAdapter(this);
		listView.setAdapter(mAdapter);
	}

	@Override
	public void build() {
		buildLayout(mParentView);
	}
	
	protected abstract void notifyDataChange();
	
	@Override
	public void refresh() {
		synchronized (mData) {
			new BuildData().execute();
		}
	}
	
	class BuildData extends AsyncTask<Void, Void, Void> {

		@Override
		protected Void doInBackground(Void... params) {
			buildData();
			return null;
		}

		@Override
		protected void onPostExecute(Void result) {
			notifyDataChange();
		}
		
	}
}
